<template>
	<view>
		<button @click="chooseImg">上传图片</button>
		<view v-for="(item, index) in imgList" :key="index">
			<image :src="item" @click="previewImg(item)"></image>
		</view>
		<!-- #ifdef H5 -->
		<view>我只希望在H5页面中看见</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<view>我只希望在微信小程序页面中看见</view>
		<!-- #endif -->
		<!-- 声明式导航 -->
		<navigator url="../detail/detail?id=80">跳转到详情页</navigator>
		<navigator url="/pages/news/news" open-type="switchTab">跳转到新闻页</navigator>
		<navigator url="../detail/detail" open-type="redirect">跳转到详情页2</navigator>
		<!-- 编程式导航 -->
		<button @click="goDetail">跳转到详情页</button>
		<button @click="goNews">跳转到新闻页</button>
		<button @click="redirectDetail">跳转到详情页</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgList: []
			}
		},
		onUnload() {
			console.log('页面卸载了')
		},
		onLoad() {
			// #ifdef H5
			console.log('我希望在H5中打印')
			// #endif
			// #ifdef MP-WEIXIN
			console.log('我希望在微信小程序中打印')
			// #endif
		},
		methods: {
			chooseImg() {
				uni.chooseImage({
					count: 3,
					success: res => {
						// console.log(res)
						this.imgList = res.tempFilePaths
					}
				})
			},
			previewImg(current) {
				uni.previewImage({
					current,
					urls: this.imgList,
					loop: true,
					indicator:'default'
				})
			},
			goDetail() {
				uni.navigateTo({
					url: '../detail/detail?id=20&name=duli'
				})
			},
			goNews() {
				uni.switchTab({
					url: '../news/news'
				})
			},
			redirectDetail() {
				uni.redirectTo({
					url: '../detail/detail'
				})
			}
		}
	}
</script>

<style>
/* #ifdef H5 */
view {
	color:#0000FF;
}
/* #endif */
/* #ifdef MP-WEIXIN */
view {
	color:#4CD964;
}
/* #endif */
</style>
